package hxy.bytecode.huawei;

import java.util.ArrayList;
import java.util.List;

/**
 * @author eric
 * @date 2020/4/18
 */
public class Main {
    public static void main(String[] args) {
        // 10个数，大小不一。均分成两组，每组大小差不多，求差值。
        int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

        // 从小到大排序
        for (int i = 9; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[j + 1]) {
                    int tmp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = tmp;
                }
            }
        }

        // 蛇形读取
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();


        boolean flag = false;
        int count = 0;
        list1.add(a[0]);
        list2.add(a[a.length-1]);

        for (int i = 1; i < a.length-1; i=i+2) {
                if (flag==true){
                    list1.add(a[i]);
                    list1.add(a[i+1]);
                    flag=false;
                }else{
                    list2.add(a[i]);
                    list2.add(a[i+1]);
                    flag=true;
                }
        }


        Integer sum1 = 0;
        for (Integer a1 : list1) {

            sum1 = sum1+a1;
        }

        Integer sum2 = 0;
        for (Integer a2 : list2) {
            sum2 =sum2 +a2;
        }
        Integer result = 0;
        if (sum1 >= sum2) {
            result = sum1 - sum2;
        } else {
            result = sum2 - sum1;
        }
        System.out.println(result);


    }
}
